/* eslint-disable n/no-unsupported-features/es-syntax */
const onePromise: {
  (): PromiseWithResolvers<number>;
  __promise?: PromiseWithResolvers<number>;
} = () => (onePromise.__promise ||= Promise.withResolvers<number>());

const twoPromise: {
  (): PromiseWithResolvers<number>;
  __promise?: PromiseWithResolvers<number>;
} = () => {
  const { promise, resolve, reject } = (twoPromise.__promise ||= onePromise());
  return {
    promise: new Promise((res, rej) => {
      promise
        .then((n) => n * 2)
        .then(res)
        .catch(rej);
    }),
    resolve,
    reject,
  };
};

twoPromise().promise.then((value) => console.log(value));

onePromise().resolve(1);
